package sv.mecca.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import sv.mecca.form.TratamientosForm;
import sv.mecca.modelo.OperacionesTratamientos;

public class TratamientosAction extends DispatchAction{
    OperacionesTratamientos oper = new OperacionesTratamientos();
    
    public void insertar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        oper.insertarTratamientos((TratamientosForm) form);
        request.setAttribute("error", "all.agregar");
        this.listado(mapping, form, request, response);
        }
    public void modificar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setAttribute("tratamientos",
            oper.modificarTratamientos(Integer.parseInt(request.getParameter("id"))));
        this.listado(mapping, form, request, response);
        }
    public void actualizar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        oper.actualizarTratamientos((TratamientosForm) form, Integer.parseInt(request.getParameter("id")));
        request.setAttribute("error", "all.actualizar");
        this.listado(mapping, form, request, response);
        }
    public void eliminar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        oper.EliminarTratamientos(Integer.parseInt(request.getParameter("id")));
        request.setAttribute("error", "all.eliminar");
        this.listado(mapping, form, request, response);
        }
    public void listado(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setAttribute("Tratamientos", oper.listado());
        request.getRequestDispatcher("/Definiciones/Tratamientos.jsp").forward(request, response);
        }
    }